// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "PaperZDCharacter.h"
#include "Interface/IRuleCharacter.h"
#include "Core/GameCore/TowerDefenceGameState.h"
#include "Core/GameCore/TowerDefencePlayerController.h"
#include "RuleCharacterZD.generated.h"

/**
 * 
 */
UCLASS()
class TF_20240717_API ARuleCharacterZD : public APaperZDCharacter, public IRuleCharacter
{
	GENERATED_BODY()

	// 攻击跟踪点
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="BaseAttribute", meta=(AllowPrivateAccess=true))
	USceneComponent* HomingPoint;

	// 角色信息UI
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="BaseAttribute", meta=(AllowPrivateAccess=true))
	class UWidgetComponent* Widget;

	// 开火点
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="BaseAttribute", meta=(AllowPrivateAccess=true))
	UArrowComponent* OpenFirePoint;
	
	// 射线捕捉对象（放置时的检测范围）
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="BaseAttribute", meta=(AllowPrivateAccess=true))
	class UBoxComponent* TraceShowCharacterInformation;

public:
	// 防御塔的旋转角度（2D中用不到）
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="BaseAttribute")
	FRotator TowerRotator;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="AnimAttribute")
	bool bAttack;
protected:
	virtual void BeginPlay() override;
	virtual float TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) override;
	
	virtual bool IsDeath() override;
	virtual float GetHealth() override;
	virtual float GetMaxHealth() override;
	virtual bool IsTeam() override;
	virtual EGameCharacterType::Type GetType() override;

public:
	ARuleCharacterZD();
	virtual void Tick(float DeltaSeconds) override;

	// 是否死亡，可以在蓝图中调用。
	UFUNCTION(Blueprintable, BlueprintPure, Category="Towers|Attribute")
	bool IsActive() { return IsDeath(); }

	void SetDirection(const FVector& Direction);

	
	// 获取玩家控制器
	FORCEINLINE ATowerDefencePlayerController* GetGameController() const { return GetWorld() ? GetWorld()->GetFirstPlayerController<ATowerDefencePlayerController>() : nullptr; }
	// 获取游戏状态
	FORCEINLINE ATowerDefenceGameState* GetGameState() const { return GetWorld() ? GetWorld()->GetGameState<ATowerDefenceGameState>() : nullptr; }
	//
	FORCEINLINE USceneComponent* GetHomingPoint() const { return HomingPoint; }
	//
	FORCEINLINE UArrowComponent* GetFirePoint() const { return OpenFirePoint; }
};
